package cn.wcy.design_patterns.test.Controller.demo2;

import java.time.LocalDate;
import java.time.YearMonth;

/**
 * 预算
 *
 * @author wcy
 * @date 2024/06/15
 */
public class Budget {

    private YearMonth month;
    private long amount;

    public Budget(long amount, YearMonth month) {
        this.amount = amount;
        this.month = month;
    }

    @Override
    public boolean equals(Object o) {
      Budget another = (Budget) o;
      return month.equals(another.month);
    }

    LocalDate getEnd() {
        return month.atEndOfMonth();
    }

    LocalDate getStart() {
        return month.atDay(1);
    }

    long getDaysCount() {
        return month.lengthOfMonth();
    }

    public Period getPeriod() {
        return new Period(getStart(), getEnd());
    }

    long getOverlappingAmount(Period period) {
        return amount / getDaysCount() * period.getOverlappingDaysCount(getPeriod());
    }
}
